package com.cloud.encrypting_cloud_storage.controller;

import com.cloud.encrypting_cloud_storage.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author leon
 * @Description: 主页
 * @date 2022年04月25日 20:33
 */
@Controller
@Slf4j
public class IndexController extends BaseController {
    @GetMapping({"", "/", "index"})
    public ModelAndView index(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        HttpSession session = request.getSession();
        User sessionUser = (User) session.getAttribute(userKey);
        if (sessionUser == null) {
            modelAndView.setViewName("redirect:/login");
            return modelAndView;
        }
        modelAndView.setViewName("main/main");
        modelAndView.addObject(userKey, sessionUser);
        return modelAndView;
    }
}
